package com.effort.com.effort.excle.interceptor;

import com.effort.com.effort.excle.core.exception.ParamException;
import com.effort.com.effort.excle.core.util.ServletUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 基础的拦截注解处理器
 *
 * @author xulu
 */
@Component
@Aspect
@Slf4j
public class PageHandlerAspect {


    @Pointcut("@annotation(com.effort.com.effort.excle.interceptor.NeedConnect)")
    public void pagePoint() {
    }

    /**
     * 实现拦截
     *
     * @return
     */
    @SuppressWarnings("rawtypes")
    @Around(value = "pagePoint()")
    public Object pageAround(ProceedingJoinPoint jp) throws Throwable {
        String key = ServletUtils.getRequest().getParameter("key");
        if (StringUtils.isEmpty(key)) {
            throw new ParamException("未连接或者连接失效,请重新连接");
        }
        return jp.proceed();
    }


}
